package com.whfc.mach.config;

import com.whfc.entity.dto.msg.PushMsgDTO;
import com.whfc.mach.dto.AppMachDataLogCacheDTO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/11/1 14:59
 */
@Configuration
public class MachRedisConfig {

    @Bean
    public RedisTemplate<String, AppMachDataLogCacheDTO> machDataTemplate(RedisConnectionFactory connectionFactory) {
        Jackson2JsonRedisSerializer redisSerializer = new Jackson2JsonRedisSerializer(AppMachDataLogCacheDTO.class);
        RedisTemplate<String, AppMachDataLogCacheDTO> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(redisSerializer);
        return redisTemplate;
    }

    @Bean
    public RedisTemplate<String, PushMsgDTO> redisTemplate(RedisConnectionFactory connectionFactory) {
        Jackson2JsonRedisSerializer redisSerializer = new Jackson2JsonRedisSerializer(PushMsgDTO.class);
        RedisTemplate<String, PushMsgDTO> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(redisSerializer);
        return redisTemplate;
    }

}